﻿using System;
using System.Data;
using Titan.DAS.Client.Data;
using Titan.FIS.Enum;

namespace Titan.FIS.SampleRecd.DataOperate
{
    public class DataQuery
	{
		private static string _strSql = string.Empty;

		/// <summary>
		/// 获取班组信息
		/// </summary>
		/// <param name="type"></param>
		/// <param name="tabSource"></param>
		/// <returns></returns>
		public static string DoQueryTeamInfo(ref DataTable tabSource)
		{
			var errMsg = string.Empty;
			_strSql = @"SELECT TEAM_ID AS F_ID,TEAM_NAME AS F_NAME FROM pub_team";
			var modelQuery = DataHelper.Instance.QuerySql(Common.UserInfo.UserName, Common.UserInfo.UserPwd, _strSql);
			if (modelQuery.RSuccess)
			{
				if (modelQuery.RSource != null && modelQuery.RSource.Tables.Count > 0 && modelQuery.RSource.Tables[0].Rows.Count > 0)
					tabSource = modelQuery.RSource.Tables[0];
				else
					errMsg = "未查询到煤种信息";
			}
			else
				errMsg = string.Format("查询煤种信息失败！\r\n错误代码:{0}  错误信息:{1}", modelQuery.RStatuCode, modelQuery.RErrInfo + modelQuery.RStatuDesc);

			return errMsg;
		}
		/// <summary>
		/// 获取煤种类型信息
		/// </summary>
		/// <param name="type"></param>
		/// <param name="tabSource"></param>
		/// <returns></returns>
		public static string DoQueryCoalTypeInfo( ref DataTable tabSource)
		{
			var errMsg = string.Empty;
			_strSql = @"SELECT MATERIEL_TYPE_ID AS F_ID,MATERIEL_TYPE_NAME AS F_NAME FROM PUB_MATERIEL_TYPE WHERE IS_COAL = 1 AND MATERIEL_TYPE_ID <> '201806121149053127559615d7b67b0'";
			var modelQuery = DataHelper.Instance.QuerySql(Common.UserInfo.UserName, Common.UserInfo.UserPwd, _strSql);
			if (modelQuery.RSuccess)
			{
				if (modelQuery.RSource != null && modelQuery.RSource.Tables.Count > 0 && modelQuery.RSource.Tables[0].Rows.Count > 0)
					tabSource = modelQuery.RSource.Tables[0];
				else
					errMsg = "未查询到物料类型信息";
			}
			else
				errMsg = string.Format("查询物料类型信息失败！\r\n错误代码:{0}  错误信息:{1}", modelQuery.RStatuCode, modelQuery.RErrInfo + modelQuery.RStatuDesc);

			return errMsg;
		}
		/// <summary>
		/// 获取煤种信息
		/// </summary>
		/// <param name="type"></param>
		/// <param name="tabSource"></param>
		/// <returns></returns>
		public static string DoQueryCoalInfo(string type, ref DataTable tabSource)
		{
			var errMsg = string.Empty;
			_strSql = @"SELECT MATERIEL_ID AS F_ID,MATERIEL_NAME AS F_NAME FROM V_PUB_MATERIEL WHERE 1 = 1";
			if (!string.IsNullOrEmpty(type))
				_strSql += string.Format(" AND MATERIEL_TYPE_ID ='{0}' ", type);

			var modelQuery = DataHelper.Instance.QuerySql(Common.UserInfo.UserName, Common.UserInfo.UserPwd, _strSql);
			if (modelQuery.RSuccess)
			{
				if (modelQuery.RSource != null && modelQuery.RSource.Tables.Count > 0 && modelQuery.RSource.Tables[0].Rows.Count > 0)
					tabSource = modelQuery.RSource.Tables[0];
				else
					errMsg = "未查询到物料信息";
			}
			else
				errMsg = string.Format("查询物料信息失败！\r\n错误代码:{0}  错误信息:{1}", modelQuery.RStatuCode, modelQuery.RErrInfo + modelQuery.RStatuDesc);

			return errMsg;
		}
		/// <summary>
		/// 获取供应商信息
		/// </summary>
		/// <param name="type"></param>
		/// <param name="tabSource"></param>
		/// <returns></returns>
		public static string DoQuerySupplierInfo(string type, ref DataTable tabSource)
		{
			var errMsg = string.Empty;
			_strSql = @"SELECT SUPPLIER_ID AS F_ID,SUPPLIER_NAME AS F_NAME FROM V_PUB_SUPPLIERMETERIEL WHERE ENABLED = 1 ";
			if (!string.IsNullOrEmpty(type))
				_strSql += string.Format(" AND MATERIEL_ID ='{0}' ", type);

			var modelQuery = DataHelper.Instance.QuerySql(Common.UserInfo.UserName, Common.UserInfo.UserPwd, _strSql);
			if (modelQuery.RSuccess)
			{
				if (modelQuery.RSource != null && modelQuery.RSource.Tables.Count > 0 && modelQuery.RSource.Tables[0].Rows.Count > 0)
					tabSource = modelQuery.RSource.Tables[0];
				else
					errMsg = "未查询到供应商信息";
			}
			else
				errMsg = string.Format("查询供应商信息失败！\r\n错误代码:{0}  错误信息:{1}", modelQuery.RStatuCode, modelQuery.RErrInfo + modelQuery.RStatuDesc);

			return errMsg;
		}

		/// <summary>
		/// 查询自检样信息
		/// </summary>
		/// <param name="strRfid"></param>
		/// <param name="tabSource"></param>
		/// <returns></returns>
		public static string DoQuerySelfSampleInfo(string strDate, string strType, string strCoal, string strSupplier, string strTeam, string strRfid, ref DataTable tabSource)
		{
			var errMsg = string.Empty;
			_strSql = @"SELECT ROWNUM AS NO, A.*
						  FROM (SELECT DISTINCT TO_CHAR(SAMPLE_TIME, 'YYYY-MM-DD') AS SAMPLE_TIME,
									   TYPE_STR AS TYPE,
									   MAKE_CODE AS BATCH_CODE,
									   --MAKE_CODE,
									   MATERIEL_NAME,
									   SUPPLIER_NAME,
									   TEAM_NAME,
									   RFID,
									   SAMPLE_USER_NAME AS USER_NAME,
									   TO_CHAR(TIME, 'YYYY-MM-DD HH24:MI:SS') AS TIME
								  FROM V_SELF_SAMPLING
								 WHERE 1=1
								";
			if (!string.IsNullOrEmpty(strDate))
			{
				_strSql += string.Format(" AND SAMPLE_TIME >= TO_DATE('{0}','YYYY-MM-DD HH24:MI:SS')", strDate + " 00:00:00");
				_strSql += string.Format(" AND SAMPLE_TIME <= TO_DATE('{0}','YYYY-MM-DD HH24:MI:SS')", strDate + " 23:59:59");
			}
			if (!string.IsNullOrEmpty(strType))
				_strSql += string.Format(" AND Type ={0} ", strType);
			if (!string.IsNullOrEmpty(strCoal))
				_strSql += string.Format(" AND MATERIEL_ID ='{0}' ", strCoal);
			if (!string.IsNullOrEmpty(strSupplier))
				_strSql += string.Format(" AND SUPPLIER_ID ='{0}' ", strSupplier);
			if (!string.IsNullOrEmpty(strTeam))
				_strSql += string.Format(" AND TEAM_ID ='{0}' ", strTeam);
			if (!string.IsNullOrEmpty(strRfid))
				_strSql += string.Format(" AND RFID ='{0}' ", strRfid);
			_strSql += string.Format("  ORDER BY TIME DESC) A");
			var modelQuery = DataHelper.Instance.QuerySql(Common.UserInfo.UserName, Common.UserInfo.UserPwd, _strSql);
			if (modelQuery.RSuccess)
			{
				if (modelQuery.RSource != null && modelQuery.RSource.Tables.Count > 0 && modelQuery.RSource.Tables[0].Rows.Count > 0)
					tabSource = modelQuery.RSource.Tables[0];
				else
					errMsg = "未查询到自检样信息";
			}
			else
				errMsg = string.Format("查询自检样信息失败！\r\n错误代码:{0}  错误信息:{1}", modelQuery.RStatuCode, modelQuery.RErrInfo + modelQuery.RStatuDesc);

			return errMsg;
		}


		/// <summary>
		/// 根据RFID查询样桶信息
		/// </summary>
		/// <param name="strRfid"></param>
		/// <param name="tabSource"></param>
		/// <returns></returns>
		public static string DoQueryPailInfo(string strRfid, ref DataTable tabSource)
		{
			var errMsg = string.Empty;
			_strSql = @"SELECT MATERIEL_NAME, SUPPLIER_NAME, TRANSPORT_NAME, BATCH_CODE
                              FROM V_CY_ALL_SAMPLING A
                              LEFT JOIN V_RC_SAMPLING B
                                ON A.BATCH_CODE = B.BATCH_CODE
                               AND A.SAMPLE_CODE = B.SAMPLE_CODE
                               AND A.RFID = B.RFID
                               AND A.REVICED = B.REVICED
                               WHERE  REVICED = 0  ";
			if (!string.IsNullOrEmpty(strRfid))
				_strSql += string.Format(" AND RFID ='{0}' ", strRfid);

			var modelQuery = DataHelper.Instance.QuerySql(Common.UserInfo.UserName, Common.UserInfo.UserPwd, _strSql);
			if (modelQuery.RSuccess)
			{
				if (modelQuery.RSource != null && modelQuery.RSource.Tables.Count > 0 && modelQuery.RSource.Tables[0].Rows.Count > 0)
					tabSource = modelQuery.RSource.Tables[0];
				else
					errMsg = "未查询到样桶信息";
			}
			else
				errMsg = string.Format("查询样桶信息失败！\r\n错误代码:{0}  错误信息:{1}", modelQuery.RStatuCode, modelQuery.RErrInfo + modelQuery.RStatuDesc);
		
			return errMsg;
		}

		/// <summary>
		/// 查询24小时内收样信息
		/// </summary>
		/// <param name="strRfid"></param>
		/// <param name="tabSource"></param>
		/// <returns></returns>
		public static string DoQueryCollectSampleInfo(ref DataTable tabSource)
		{
			var errMsg = string.Empty;
			_strSql = @"SELECT ROWNUM AS NO, A.*
						   FROM (SELECT DISTINCT A.COLLECT_CODE,
												 C.MATERIEL_NAME || D.MATERIEL_NAME AS MATERIEL_NAME,
												 C.SUPPLIER_NAME || D.SUPPLIER_NAME AS SUPPLIER_NAME,
												 A.RFID,
												 B.TRUENAME AS R_USER_NAME,
												 TO_CHAR(A.RECEIVE_TIME,
														 'YYYY-MM-DD HH24:MI:SS') AS RECEIVE_TIME
								   FROM S_COLLECTSAMPLE A
								   LEFT JOIN SYSUSER B
									 ON A.R_USER_ID = B.ID
								   LEFT JOIN V_PL_RC_DETAILS C
									 ON A.BATCH_CODE = C.BATCH_CODE                       
								   LEFT JOIN V_SELF_SAMPLING D
									 ON A.BATCH_CODE = D.BATCH_CODE
								  WHERE RECEIVE_TIME > SYSDATE - 1
								  ORDER BY RECEIVE_TIME DESC) A";
			var modelQuery = DataHelper.Instance.QuerySql(Common.UserInfo.UserName, Common.UserInfo.UserPwd, _strSql);
			if (modelQuery.RSuccess)
			{
				if (modelQuery.RSource != null && modelQuery.RSource.Tables.Count > 0 && modelQuery.RSource.Tables[0].Rows.Count > 0)
					tabSource = modelQuery.RSource.Tables[0];
				else
					errMsg = "未查询到收样信息";
			}
			else
				errMsg = string.Format("查询收样信息失败！\r\n错误代码:{0}  错误信息:{1}", modelQuery.RStatuCode, modelQuery.RErrInfo + modelQuery.RStatuDesc);

			return errMsg;
		}

		/// <summary>
		/// 查询物料对应的化验复检指标
		/// </summary>
		public static string DoQueryReTestIndex(string strIsTest, string strIsCheck, ref DataTable tabSource)
		{
			var errMsg = string.Empty;
			_strSql = string.Format(@"select A.MATERIEL_ID,
										   A.MATERIEL_NAME,
										   A.MATERIEL_TYPE_ID,
										   A.LMS_TEMPLATE_ID,
										   A.INDEX_ID,
										   A.INDEX_CODE,
										   A.INDEX_DISNAME,
										   A.VALUE_BASE,
										   A.VALUE_MIN,
										   A.VALUE_MAX,
										   A.VALUE_TEST,
										   A.VALUE_CHECK,
										   A.VALUE_TYPE,
										   A.VALUE_SHOW from v_materiel_lms_recheck A where 1 = 1 ");
			if (!string.IsNullOrEmpty(strIsTest)) _strSql += " and A.VALUE_TEST = " + strIsTest;
			if (!string.IsNullOrEmpty(strIsCheck)) _strSql += " and A.VALUE_CHECK = " + strIsCheck;
			var modelQuery = DataHelper.Instance.QuerySql(Common.UserInfo.UserName, Common.UserInfo.UserPwd, _strSql);
			if (modelQuery.RSuccess)
			{
				if (modelQuery.RSource != null && modelQuery.RSource.Tables.Count > 0 && modelQuery.RSource.Tables[0].Rows.Count > 0)
					tabSource = modelQuery.RSource.Tables[0];
				else
					errMsg = "查询完毕，未找到化验和复检指标相关数据！";
			}
			else
				errMsg = string.Format("查询化验和复检指标信息失败！\r\n错误代码:{0}  错误信息:{1}", modelQuery.RStatuCode, modelQuery.RErrInfo + modelQuery.RStatuDesc);
			return errMsg;
		}
		
		/// <summary>
		/// 根据收样号或者批次号查询物料信息 
		/// strMode 0:收样编码，1:批次编码，2人工采样编码,6制样编码
		/// </summary>
		public static string DoQueryMateriel(string strMode, string strCode, ref DataTable tabSource)
		{
			var errMsg = string.Empty;
			if (strMode == "0")
				_strSql = string.Format(@"SELECT DISTINCT A.SAMPLE_CODE AS MAKE_CODE, B.BATCH_TYPE, B.MATERIEL_TYPE_ID, B.MATERIEL_TYPE_NAME, B.MATERIEL_ID,A.RECEIVE_TIME
									  FROM S_COLLECTSAMPLE A
									  LEFT JOIN V_PL_ALL_DETAILS B
										ON A.BATCH_CODE = B.BATCH_CODE
									 WHERE A.COLLECT_CODE = '{0}'
									   AND TO_NUMBER(TO_CHAR(A.RECEIVE_TIME, 'YYMMDD')) >=
                                           TO_NUMBER(TO_CHAR(SYSDATE - 1 / 24 * 6, 'YYMMDD'))
							      ORDER BY A.RECEIVE_TIME ASC ", strCode); //早上6点以前可以处理昨天一整天的批次，解决跨天问题
			else if (strMode == "1")
				_strSql = string.Format(@"SELECT B.BATCH_CODE AS MAKE_CODE, B.BATCH_TYPE, B.MATERIEL_TYPE_ID, B.MATERIEL_TYPE_NAME, B.MATERIEL_ID
									  FROM V_PL_ALL_DETAILS B
									 WHERE B.BATCH_CODE = '{0}'", strCode);
			else if (strMode == "2")
				_strSql = string.Format(@"SELECT B.BATCH_CODE AS MAKE_CODE, B.BATCH_TYPE, B.MATERIEL_TYPE_ID, B.MATERIEL_TYPE_NAME, B.MATERIEL_ID
									  FROM V_PL_ALL_DETAILS B
									 WHERE B.ARTIFICIAL_CODE = '{0}'", strCode);
			else if (strMode == "6")
				_strSql = string.Format(@"SELECT B.MAKE_CODE, B.BATCH_TYPE, B.MATERIEL_TYPE_ID, B.MATERIEL_TYPE_NAME, B.MATERIEL_ID
									  FROM V_PL_ALL_DETAILS B
									 WHERE B.MAKE_CODE = '{0}'", strCode);
			var modelQuery = DataHelper.Instance.QuerySql(Common.UserInfo.UserName, Common.UserInfo.UserPwd, _strSql);
			if (modelQuery.RSuccess)
			{
				if (modelQuery.RSource != null && modelQuery.RSource.Tables.Count > 0 && modelQuery.RSource.Tables[0].Rows.Count > 0)
					tabSource = modelQuery.RSource.Tables[0];
				else
					errMsg = "查询完毕，未找到对应的物料信息！";
			}
			else
				errMsg = string.Format("查询对应的物料信息失败！\r\n错误代码:{0}  错误信息:{1}", modelQuery.RStatuCode, modelQuery.RErrInfo + modelQuery.RStatuDesc);
			return errMsg;
		}

	

		
		

		/// <summary>
		/// 查询样品信息
		/// </summary>
		/// <param name="strDate"></param>
		/// <param name="strCCode"></param>
		/// <param name="strRfid"></param>
		/// <param name="strSType"></param>
		/// <param name="tabSource"></param>
		/// <returns></returns>
		public static string DoQuerySampleInfo(string strDate, string strCCode, string strRfid, string strSType, LaboratoryType labType, ref DataTable tabSource)
		{
			var errMsg = string.Empty;
			_strSql = @"SELECT ROWNUM AS NO, A.*
						  FROM (SELECT DISTINCT COLLECT_CODE,
									   MAKE_CODE,
									   SAMPLE_CODE,
									   RFID,
									   SAMPLE_TYPE_STR,
									   WEIGHT,
									   to_char(CREATE_TIME,'yyyy-MM-dd HH24:mi:ss') as CREATE_TIME,
									   PRINT_COUNT,
									   WEIGHT_USER_NAME AS USER_NAME
								  FROM V_S_SAMPLE 
								 WHERE 1 = 1 ";
			if (!string.IsNullOrEmpty(strDate))
			{
				_strSql += string.Format(" AND CREATE_TIME >= TO_DATE('{0}','YYYY-MM-DD HH24:MI:SS')", strDate + " 00:00:00");
				_strSql += string.Format(" AND CREATE_TIME <= TO_DATE('{0}','YYYY-MM-DD HH24:MI:SS')", strDate + " 23:59:59");

			}
			if (!string.IsNullOrEmpty(strCCode))
				_strSql += string.Format(" AND COLLECT_CODE ='{0}' ", strCCode);
			if (!string.IsNullOrEmpty(strRfid))
				_strSql += string.Format(" AND RFID ='{0}' ", strRfid);
			if (!string.IsNullOrEmpty(strSType) && strSType != " ")
			{
				_strSql += string.Format(" AND SAMPLE_TYPE_STR = '{0}' ", strSType);
			}
			//if (labType == LaboratoryType.RC)
			//    _strSql += " AND BATCH_TYPE = '入厂煤'";
			//else if (labType == LaboratoryType.RL)
			//    _strSql += " AND BATCH_TYPE = '入炉煤'";

			_strSql += "ORDER BY CREATE_TIME DESC)A ";

			var modelQuery = DataHelper.Instance.QuerySql(Common.UserInfo.UserName, Common.UserInfo.UserPwd, _strSql);
			if (modelQuery.RSuccess)
			{
				if (modelQuery.RSource != null && modelQuery.RSource.Tables.Count > 0 && modelQuery.RSource.Tables[0].Rows.Count > 0)
					tabSource = modelQuery.RSource.Tables[0];
				else
					errMsg = "未查询到有效样品信息";
			}
			else
				errMsg = string.Format("查询样品信息失败！\r\n错误代码:{0}  错误信息:{1}", modelQuery.RStatuCode, modelQuery.RErrInfo + modelQuery.RStatuDesc);

			return errMsg;
		}

		/// <summary>
		/// 根据RFID查询样品信息
		/// </summary>
		/// <param name="strRfid"></param>
		/// <param name="tabSource"></param>
		/// <returns></returns>
		public static string DoQuerySampleInfo(string strRfid, ref DataTable tabSource)
		{
			var errMsg = string.Empty;
			_strSql = @"SELECT BATCH_CODE, SAMPLE_CODE, SAMPLE_TYPE, WEIGHT FROM S_SAMPLE WHERE 1=1 ";
			if (!string.IsNullOrEmpty(strRfid))
				_strSql += string.Format(" AND RFID ='{0}' ", strRfid);

			var modelQuery = DataHelper.Instance.QuerySql(Common.UserInfo.UserName, Common.UserInfo.UserPwd, _strSql);
			if (modelQuery.RSuccess)
			{
				if (modelQuery.RSource != null && modelQuery.RSource.Tables.Count > 0 && modelQuery.RSource.Tables[0].Rows.Count > 0)
					tabSource = modelQuery.RSource.Tables[0];
				else
					errMsg = "未查询到样品信息";
			}
			else
				errMsg = string.Format("查询样品信息失败！\r\n错误代码:{0}  错误信息:{1}", modelQuery.RStatuCode, modelQuery.RErrInfo + modelQuery.RStatuDesc);

			return errMsg;
		}

		/// <summary>
		/// 根据试样编码查询样品信息
		/// </summary>
		/// <param name="strSampleCode"></param>
		/// <param name="tabSource"></param>
		/// <returns></returns>
		public static string DoQuerySampleInfo2(string strSampleCode, ref DataTable tabSource)
		{
			var errMsg = string.Empty;
			_strSql = @"SELECT DISTINCT BATCH_CODE, SAMPLE_CODE, COLLECT_CODE, SAMPLE_TYPE, WEIGHT FROM S_SAMPLE WHERE 1=1 ";
			if (!string.IsNullOrEmpty(strSampleCode))
				_strSql += string.Format(" AND SAMPLE_CODE ='{0}' ", strSampleCode);

			var modelQuery = DataHelper.Instance.QuerySql(Common.UserInfo.UserName, Common.UserInfo.UserPwd, _strSql);
			if (modelQuery.RSuccess)
			{
				if (modelQuery.RSource != null && modelQuery.RSource.Tables.Count > 0 && modelQuery.RSource.Tables[0].Rows.Count > 0)
					tabSource = modelQuery.RSource.Tables[0];
				else
					errMsg = "未查询到样品信息";
			}
			else
				errMsg = string.Format("查询样品信息失败！\r\n错误代码:{0}  错误信息:{1}", modelQuery.RStatuCode, modelQuery.RErrInfo + modelQuery.RStatuDesc);

			return errMsg;
		}
		/// <summary>
		/// 根据RFID号查询该样桶是否已收样信息
		/// </summary>
		/// <param name="strRfid"></param>
		/// <param name="errMsg"></param>
		/// <returns></returns>
		public static bool DoCheckPail(string strRfid, ref string errMsg)
		{
			_strSql = $"SELECT * FROM V_CY_ALL_SAMPLING WHERE RFID = '{strRfid}'";
			var result = false;
			var modelQuery = DataHelper.Instance.QuerySql(Common.UserInfo.UserName, Common.UserInfo.UserPwd, _strSql);
			if (modelQuery.RSuccess)
			{
				result = true;
				if (modelQuery.RSource != null && modelQuery.RSource.Tables.Count > 0 && modelQuery.RSource.Tables[0].Rows.Count > 0)
					errMsg = "该样桶尚未收样";
			}
			else
				errMsg = string.Format("查询样品信息失败！\r\n错误代码:{0}  错误信息:{1}", modelQuery.RStatuCode, modelQuery.RErrInfo + modelQuery.RStatuDesc);
			return result;
		}

		
		/// <summary>
		/// 查询样瓶重量信息
		/// </summary>
		/// <param name="tabSource"></param>
		/// <returns></returns>
		public static string DoQuerySampleBottleWeight(ref DataTable tabSource)
		{
			var errMsg = string.Empty;
			_strSql = @"SELECT PARAMETER_KEY,PARAMETER_VALUE FROM SYS_PARAMETER WHERE PARAMETER_KEY LIKE 'Bottle%' ";

			var modelQuery = DataHelper.Instance.QuerySql(Common.UserInfo.UserName, Common.UserInfo.UserPwd, _strSql);
			if (modelQuery.RSuccess)
			{
				if (modelQuery.RSource != null && modelQuery.RSource.Tables.Count > 0 && modelQuery.RSource.Tables[0].Rows.Count > 0)
					tabSource = modelQuery.RSource.Tables[0];
				else
					errMsg = "未查询到样瓶重量";
			}
			else
				errMsg = string.Format("查询样瓶重量信息失败！\r\n错误代码:{0}  错误信息:{1}", modelQuery.RStatuCode, modelQuery.RErrInfo + modelQuery.RStatuDesc);

			return errMsg;
		}

		/// <summary>
		/// 根据RFID查询用户信息
		/// </summary>
		/// <param name="strRfid"></param>
		/// <param name="tabSource"></param>
		/// <returns></returns>
		public static string DoQueryUserInfo(string strRfid, ref DataTable tabSource)
		{
			var errMsg = string.Empty;
			_strSql = @"SELECT ID,TRUENAME FROM SYSUSER WHERE 1=1 ";
			if (!string.IsNullOrEmpty(strRfid))
				_strSql += string.Format(" AND RFID ='{0}' ", strRfid);

			var modelQuery = DataHelper.Instance.QuerySql(Common.UserInfo.UserName, Common.UserInfo.UserPwd, _strSql);
			if (modelQuery.RSuccess)
			{
				if (modelQuery.RSource != null && modelQuery.RSource.Tables.Count > 0 && modelQuery.RSource.Tables[0].Rows.Count > 0)
					tabSource = modelQuery.RSource.Tables[0];
				else
					errMsg = "未查询到用户信息";
			}
			else
				errMsg = string.Format("查询用户信息失败！\r\n错误代码:{0}  错误信息:{1}", modelQuery.RStatuCode, modelQuery.RErrInfo + modelQuery.RStatuDesc);

			return errMsg;
		}

		

		/// <summary>
		/// 查询收样信息
		/// </summary>
		/// <param name="strDate"></param>
		/// <param name="strSCode"></param>
		/// <param name="strSYUserID"></param>
		/// <param name="tabSource"></param>
		/// <returns></returns>
		public static string DoQueryReceiveSampleInfo(string strDate, string strSCode, string strSYUserID, LaboratoryType labType, ref DataTable tabSource)
		{
			var errMsg = string.Empty;
			_strSql = @"SELECT ROWNUM AS NO, A.*
						  FROM (SELECT DISTINCT BATCH_CODE,
									   MATERIEL_TYPE_NAME,
									   NEEDLMSINDEXS AS TYPE,
									   --MAKE_CODE,
									   TEST_CODE,
									   SAMPLE_CODE,
									   COLLECT_CODE,
									   COLLECT_ORDER,
									   WEIGHT AS SAMPLE_WEIGHT,
									   RFID,
									   SAMPLE_TYPE,
									   SAMPLE_TYPE_STR,
									   --to_char(SAMPLING_BEGIN_TIME, 'yyyy-MM-dd HH24:mi:ss') as SAMPLING_BEGIN_TIME,
									   --to_char(SAMPLING_END_TIME, 'yyyy-MM-dd HH24:mi:ss') as SAMPLING_END_TIME,
									   to_char(MAKE_TIME, 'yyyy-MM-dd HH24:mi:ss') as MAKE_TIME,
									   MAKE_USER_TRUENAME,
									   SEND_USER_TRUENAME,
									   COLLECT_USER_TRUENAME,
									   to_char(COLLECT_TIME, 'yyyy-MM-dd HH24:mi:ss') as COLLECT_TIME,
									   PRINT_COUNT
								  FROM V_LMS_COLLECTSAMPLE
								 WHERE 1 = 1  ";
			if (!string.IsNullOrEmpty(strDate))
			{
				_strSql += string.Format(" AND COLLECT_TIME >= TO_DATE('{0}','YYYY-MM-DD HH24:MI:SS')", strDate + " 00:00:00");
				_strSql += string.Format(" AND COLLECT_TIME <= TO_DATE('{0}','YYYY-MM-DD HH24:MI:SS')", strDate + " 23:59:59");

			}
			if (!string.IsNullOrEmpty(strSCode))
				_strSql += string.Format(" AND SAMPLE_CODE = '{0}' ", strSCode);
			if (!string.IsNullOrEmpty(strSYUserID))
				_strSql += string.Format(" AND SEND_USER_ID = '{0}' ", strSYUserID);
			//if (labType == LaboratoryType.RC)
			//    _strSql += " AND BATCH_TYPE = '入厂煤'";
			//else if (labType == LaboratoryType.RL)
			//    _strSql += " AND BATCH_TYPE = '入炉煤'";

			_strSql += "ORDER BY COLLECT_TIME DESC )A";

			var modelQuery = DataHelper.Instance.QuerySql(Common.UserInfo.UserName, Common.UserInfo.UserPwd, _strSql);
			if (modelQuery.RSuccess)
			{
				if (modelQuery.RSource != null && modelQuery.RSource.Tables.Count > 0 && modelQuery.RSource.Tables[0].Rows.Count > 0)
					tabSource = modelQuery.RSource.Tables[0];
				else
					errMsg = "未查询到有效收样信息";
			}
			else
				errMsg = string.Format("查询收样信息失败！\r\n错误代码:{0}  错误信息:{1}", modelQuery.RStatuCode, modelQuery.RErrInfo + modelQuery.RStatuDesc);

			return errMsg;
		}

	}
}
